﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:Root="clr-namespace:Elysium.Theme">

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="/Elysium.Theme;component/Themes/SharedResources.xaml"/>
    </ResourceDictionary.MergedDictionaries>

    <Style x:Key="SliderRepeatButtonStyle" TargetType="{x:Type RepeatButton}">

        <Setter Property="Background" Value="{StaticResource ForegroundMiddlelight}"/>

        <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
        <Setter Property="Focusable" Value="False"/>

        <Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
        <Setter Property="Stylus.IsPressAndHoldEnabled" Value="False"/>

        <Setter Property="OverridesDefaultStyle" Value="True"/>
        <Setter Property="SnapsToDevicePixels" Value="True"/>

        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type RepeatButton}">
                    <Rectangle Fill="{TemplateBinding Background}"
                               StrokeThickness="0"
                               Width="{TemplateBinding Width}"
                               Height="{TemplateBinding Height}"
                               SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        
        <Style.Triggers>            
            <Trigger Property="IsEnabled" Value="False">
                <Setter Property="Background" Value="{StaticResource Disabled}"/>
            </Trigger>            
        </Style.Triggers>
        
    </Style>
    
    <Style x:Key="SliderRepeatButtonValuableStyle" TargetType="{x:Type RepeatButton}" BasedOn="{StaticResource SliderRepeatButtonStyle}">
        <Setter Property="Background" Value="{StaticResource Accent}"/>
    </Style>

    <Style x:Key="SliderThumbStyle" TargetType="{x:Type Thumb}">
        
        <Setter Property="Background" Value="{StaticResource ForegroundMiddlelight}"/>
        <Setter Property="BorderBrush" Value="{StaticResource Background}"/>

        <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
        <Setter Property="Focusable" Value="False"/>

        <Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
        <Setter Property="Stylus.IsPressAndHoldEnabled" Value="False"/>

        <Setter Property="OverridesDefaultStyle" Value="True"/>
        <Setter Property="SnapsToDevicePixels" Value="True"/>

        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Thumb}">
                    <Border Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            Width="{TemplateBinding Width}"
                            Height="{TemplateBinding Height}"
                            SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        
        <Style.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter Property="Background" Value="{StaticResource ForegroundLowlight}"/>
            </Trigger>
            <Trigger Property="IsDragging" Value="True">
                <Setter Property="Background" Value="{StaticResource ForegroundLowlight}"/>
            </Trigger>
            <Trigger Property="IsEnabled" Value="False">
                <Setter Property="Background" Value="{StaticResource Disabled}"/>
            </Trigger>            
        </Style.Triggers>

    </Style>

    <ControlTemplate x:Key="HorizontalSliderTemplate" TargetType="{x:Type Slider}">
        <Grid Background="{TemplateBinding Background}"
              SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <TickBar Grid.Row="0"
                     Fill="{TemplateBinding BorderBrush}"
                     Placement="Top"
                     Height="{TemplateBinding Root:Parameters.SliderTrackSize}"
                     Visibility="Collapsed"/>
            <Rectangle x:Name="PART_SelectionRange"
                       Grid.Row="1"
                       Fill="{StaticResource Foreground}"
                       StrokeThickness="0"
                       Height="{TemplateBinding Root:Parameters.SliderTrackSize}"
                       Visibility="Hidden"/>
            <Track x:Name="PART_Track"
                   Grid.Row="1"
                   HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                <Track.DecreaseRepeatButton>
                    <RepeatButton Command="{x:Static Slider.DecreaseLarge}"
                                  IsEnabled="{TemplateBinding IsEnabled}"
                                  Height="{TemplateBinding Root:Parameters.SliderTrackSize}"
                                  Style="{StaticResource SliderRepeatButtonValuableStyle}"/>
                </Track.DecreaseRepeatButton>
                <Track.Thumb>
                    <Thumb IsEnabled="{TemplateBinding IsEnabled}"
                           Width="{TemplateBinding Root:Parameters.SliderThumbThickness}"
                           Height="{TemplateBinding Height}"
                           Style="{StaticResource SliderThumbStyle}">
                        <Thumb.BorderThickness>
                            <Thickness Left="0"
                                       Top="0"
                                       Right="{x:Static Root:Parameters.DefaultStrokeThickness}"
                                       Bottom="0"/>
                        </Thumb.BorderThickness>
                    </Thumb>
                </Track.Thumb>
                <Track.IncreaseRepeatButton>
                    <RepeatButton Command="{x:Static Slider.IncreaseLarge}"
                                  IsEnabled="{TemplateBinding IsEnabled}"
                                  Height="{TemplateBinding Root:Parameters.SliderTrackSize}"
                                  Style="{StaticResource SliderRepeatButtonStyle}"/>
                </Track.IncreaseRepeatButton>
            </Track>
            <TickBar Grid.Row="2"
                     Fill="{TemplateBinding BorderBrush}"
                     Placement="Bottom"
                     Height="{TemplateBinding Root:Parameters.SliderTrackSize}"
                     Visibility="Collapsed"/>
        </Grid>
    </ControlTemplate>

    <ControlTemplate x:Key="VerticalSliderTemplate" TargetType="{x:Type Slider}">
        <Grid Background="{TemplateBinding Background}"
              SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>
            <TickBar Grid.Column="0"
                     Fill="{TemplateBinding BorderBrush}"
                     Placement="Top"
                     Width="{TemplateBinding Root:Parameters.SliderTrackSize}"
                     Visibility="Collapsed"/>
            <Rectangle x:Name="PART_SelectionRange"
                       Grid.Column="1"
                       Fill="{StaticResource Foreground}"
                       StrokeThickness="0"
                       Width="{TemplateBinding Root:Parameters.SliderTrackSize}"
                       Visibility="Hidden"/>
            <Track x:Name="PART_Track"
                   Grid.Column="1"
                   HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                <Track.DecreaseRepeatButton>
                    <RepeatButton Command="{x:Static Slider.DecreaseLarge}"
                                  IsEnabled="{TemplateBinding IsEnabled}"
                                  Width="{TemplateBinding Root:Parameters.SliderTrackSize}"
                                  Style="{StaticResource SliderRepeatButtonValuableStyle}"/>
                </Track.DecreaseRepeatButton>
                <Track.Thumb>
                    <Thumb IsEnabled="{TemplateBinding IsEnabled}"
                           Width="{TemplateBinding Width}"
                           Height="{TemplateBinding Root:Parameters.SliderThumbThickness}"
                           Style="{StaticResource SliderThumbStyle}">
                        <Thumb.BorderThickness>
                            <Thickness Left="0"
                                       Top="{x:Static Root:Parameters.DefaultStrokeThickness}"
                                       Right="0"
                                       Bottom="0"/>
                        </Thumb.BorderThickness>
                    </Thumb>
                </Track.Thumb>
                <Track.IncreaseRepeatButton>
                    <RepeatButton Command="{x:Static Slider.IncreaseLarge}"
                                  IsEnabled="{TemplateBinding IsEnabled}"
                                  Width="{TemplateBinding Root:Parameters.SliderTrackSize}"
                                  Style="{StaticResource SliderRepeatButtonStyle}"/>
                </Track.IncreaseRepeatButton>
            </Track>
            <TickBar Grid.Column="2"
                     Fill="{TemplateBinding BorderBrush}"
                     Placement="Bottom"
                     Width="{TemplateBinding Root:Parameters.SliderTrackSize}"
                     Visibility="Collapsed"/>
        </Grid>
    </ControlTemplate>

    <Style TargetType="{x:Type Slider}">

        <Setter Property="Background" Value="{StaticResource Transparent}"/>
        <Setter Property="BorderBrush" Value="{StaticResource ForegroundMiddlelight}"/>
        <Setter Property="BorderThickness" Value="0"/>
        <Setter Property="Foreground" Value="{StaticResource Foreground}"/>
        <Setter Property="FontFamily" Value="{x:Static Root:Parameters.FontFamily}"/>
        <Setter Property="FontSize" Value="{x:Static Root:Parameters.TextFontSize}"/>
        <Setter Property="FontWeight" Value="Normal"/>

        <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
        <Setter Property="Focusable" Value="False"/>
        
        <Setter Property="Stylus.IsPressAndHoldEnabled" Value="False"/>

        <Setter Property="OverridesDefaultStyle" Value="True"/>
        <Setter Property="SnapsToDevicePixels" Value="True"/>

        <Style.Triggers>
            
            <Trigger Property="IsEnabled" Value="False">
                <Setter Property="BorderBrush" Value="{StaticResource Disabled}"/>
            </Trigger>
            
            <Trigger Property="Orientation" Value="Horizontal">
                
                <Setter Property="MinHeight" Value="14"/>
                <Setter Property="Height" Value="18"/>
                <Setter Property="MaxHeight" Value="22"/>
                
                <Setter Property="Template" Value="{StaticResource HorizontalSliderTemplate}"/>

            </Trigger>
            
            <Trigger Property="Orientation" Value="Vertical">
                
                <Setter Property="MinWidth" Value="14"/>
                <Setter Property="Width" Value="18"/>
                <Setter Property="MaxWidth" Value="22"/>
                
                <Setter Property="Template" Value="{StaticResource VerticalSliderTemplate}"/>   
                
            </Trigger>
            
        </Style.Triggers>

    </Style>

</ResourceDictionary>